import openai

openai.api_key = "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"


def generate_response(prompt):
    response = openai.Completion.create(
        engine="text-davinci-002",
        prompt=prompt,
        max_tokens=150,
        stop=["\n"]
    )
    return response['choices'][0]['text'].strip()


def chat_with_gpt3():
    print("Chat with GPT-3. Type 'exit' to end the conversation.")
    user_input = input("You: 你是版本几？")

    while user_input.lower() != "exit":
        prompt = f"You: {user_input}\nGPT-3:"
        response = generate_response(prompt)
        print(response)

        user_input = input("You: ")


if __name__ == "__main__":
    chat_with_gpt3()
